
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

mx_eyelink_wait_for_mode_ready = binder_py('mx_eyelink_wait_for_mode_ready')
mx_eyelink_wait_for_mode_ready.mx_c.headers = ['<eyelink.h>','"mex.h"','"utils.h"']
mx_eyelink_wait_for_mode_ready.bindo += ['utils.o']
mx_eyelink_wait_for_mode_ready.mx_c.code = \
"""
INT16 _main( UINT32 msec )
{
    return eyelink_wait_for_mode_ready( msec );
}


void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{

    mwSize td[2] = {1,1};
    double *status;
    int msec;    
    
    /* Verify input arguments. */
    if(nrhs != 1 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 1 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    if ( isscalar( prhs[0] ) ){
        INT16 scalar;
        /* Returns the scalar, casts to int if necessary. Returns 0 if */
        /* input is complex. */
        if ( returnscalar( prhs[0], &msec ) != 1 )
            mexErrMsgTxt("Complex data is not supported.");
        if (msec < 0)
            mexErrMsgTxt("msec should be positive.");                   
    } else {
        mexErrMsgTxt("msec should be a scalar."); 
    } 
    
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);    
    *status = (double ) _main( (UINT32 ) msec ); 
    return;    
}
"""

mx_eyelink_wait_for_mode_ready.mx_c.mdoc = \
"""function [ ] = mx_eyelink_wait_for_mode_ready( )
%MX_EYELINK_WAIT_FOR_MODE_READY After a mode-change command is given to the EyeLink
% tracker, an additional 5 to 30 milliseconds may be needed to complete mode setup. 
% Call this function after mode change functions.
%
% Remarks:
% If it does not return 0, assume a tracker error has occurred.
% Parameters:
% maxwait 	Maximum milliseconds to wait for the mode to change.
% Returns:
% 0 if mode switching is done, else still waiting.
%
"""
mx_eyelink_wait_for_mode_ready.write_c()
mx_eyelink_wait_for_mode_ready.write_m()
mx_eyelink_wait_for_mode_ready.compile()
mx_eyelink_wait_for_mode_ready.write_sh()

